<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="commons/css::css">head</th:block>
</head>

<body class="flat-blue">
<i style="display: none;" id="_manager_url" url="/role/manager"></i>
<div class="app-container">
    <div class="row content-container">
        <th:block th:include="commons/nav_head::nav">head</th:block>
        <th:block th:include="commons/side::side">side</th:block>
        <!-- Main Content -->
        <div class="container-fluid">
            <div class="side-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <label th:text="${role.id}?'修改':'添加'"></label>角色
                            </div>
                            <div class="panel-body form-group">
                                <form class="form-horizontal" role="form" id="actionForm" name="actionForm" method="post" th:action="@{/role/saveRole}">
                                    <div class="form-group">
                                        <label for="roleName" class="col-sm-2 control-label">角色名称</label>
                                        <div class="col-sm-4">
                                            <input type="hidden" id="id" name="id" th:value="${role.id}">
                                            <input type="text" class="form-control required" id="roleName" name="roleName" th:value="${role.roleName}" placeholder="请输入角色名称">
                                        </div>
                                    </div>

                                    <!--<div class="form-group">
                                        <label for="roleCode" class="col-sm-2 control-label">角色编码</label>
                                        <div class="col-sm-4">
                                            <input type="text" class="form-control" id="roleCode" name="roleCode" th:readonly="${role}?readonly" th:value="${role}?${role.roleCode}" placeholder="请输入编码" required>
                                        </div>
                                    </div>-->

                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-3">
                                            <button type="button" class="btn btn-info" id="btn-submit">
                                                <span class="fa fa-adjust"> 提交</span>
                                            </button>
                                            <button type="button" class="btn btn-info" onclick="document.location.replace(ctx + '/role/manager');">
                                                <span class="glyphicon glyphicon-backward"> 返回</span>
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<th:block th:include="commons/js::js">Javascript Libs</th:block>
<script type="text/javascript">

    $(function () {

        $("#btn-submit").click(function () {
            // 提交表单
            var actionForm = $("#actionForm");
            var valid = actionForm.valid();
            if (!valid) {
                return;
            }
            actionForm.ajaxSubmit(function (rtn) {
                if(rtn.code != 1) {
                    Alert(rtn.message);
                    return;
                }
                Alert("操作成功", function () {
                    document.location.replace(ctx + "/role/manager");
                });
            })
        });
    });
</script>
</html>